package prototype;

import java.util.Hashtable;

/**
 * @author 许群星
 * @decription 创建一个实体类，从数据库获取实体类，并把他们存储在HashTable中
 * @data 2020/2/1719:34
 **/
public class ShapeCache {
    private static Hashtable<String,Shape> shapeMap
            =new Hashtable<>();

    public static Shape getShape(String shapeId){
        Shape cachedShape=shapeMap.get(shapeId);
        return (Shape) cachedShape.clone();
    }

    //对于每一种形状都运行数据库查询，并创建改形状
    //shapeMap.put(shapeKey,shape)
    public static void loadCache(){
        Circle circle=new Circle();
        circle.setId("1");
        shapeMap.put(circle.getId(),circle);

        Sqare sqare=new Sqare();
        sqare.setId("2");
        shapeMap.put(sqare.getId(),sqare);

        Rectangle rectangle=new Rectangle();
        rectangle.setId("3");
        shapeMap.put(rectangle.getId(),rectangle);
    }
}
